import request from '@/utils/request';
import { ProductQuery, ProductForm, ProductVo } from './types';
import { TableDataInfo, R } from '@/api/types';
import { AxiosPromise } from 'axios';

// 查询产品列表
export function listProduct(query: ProductQuery): Promise<TableDataInfo<ProductVo>> {
  return request({
    url: '/product/product/list',
    method: 'get',
    params: query
  });
}

// 查询产品详细
export function getProduct(id: string | number): Promise<R<ProductVo>> {
  return request({
    url: `/product/product/${id}`,
    method: 'get'
  });
}

// 新增产品
export function addProduct(data: ProductForm): Promise<R<void>> {
  return request({
    url: '/product/product',
    method: 'post',
    data: data
  });
}

// 修改产品
export function updateProduct(data: ProductForm): Promise<R<void>> {
  return request({
    url: '/product/product',
    method: 'put',
    data: data
  });
}

// 删除产品
export function delProduct(ids: string | number | Array<string | number>): Promise<R<void>> {
  return request({
    url: `/product/product/${ids}`,
    method: 'delete'
  });
}

// 上传产品图片
export function uploadProductImage(productId: number, file: File): Promise<R<string>> {
  const formData = new FormData();
  formData.append('file', file);
  return request({
    url: `/product/product/uploadImage/${productId}`,
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data: formData
  });
} 